home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12196 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  41 lines

  1. Path: garden.csc.calpoly.edu!not-for-mail
  2. From: dstubbs@garden.csc.calpoly.edu (Dan Stubbs)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginer C please help me
  5. Date: 29 Mar 1996 08:32:40 -0800
  6. Organization: Cal Poly, San Luis Obispo
  7. Message-ID: <4jh3b8$e5q@garden.csc.calpoly.edu>
  8. References: <DoLCFx.B7x.0.bloor@torfree.net> <4iq6uc$evq@daryl.scsn.net> <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de> <4jeljl$8cg_001@nuts.nwu.edu>
  9. NNTP-Posting-User: dstubbs@garden.csc.calpoly.edu
  10.  
  11. In article <4jeljl$8cg_001@nuts.nwu.edu>, Laurie Long <llong@nwu.edu> wrote:
  12. >In article <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de>,
  13. >   schoof@informatik.uni-wuerzburg.de (Jochen Schoof) wrote:
  14. >>Scott Shrader (shrader@scsn.net) wrote:
  15. >>: In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net says...
  16. >>: >
  17. >>: >#include <stdio.h>
  18. >>: >#include <math.h>
  19. >>: >main ()
  20. >>: >{
  21. >>: >float n;
  22. >>: >n=(9/5);
  23. >>: >printf ("n=   %1.3f\n", n);
  24. >>: >}
  25. >>: >I have complied and run the programme & I got the answer n=1.000
  26. >>: >-- 
  27. >>:What you are asking the program to do is convert an int value (9/5 = 1) to a 
  28. > float.  You need to type cast either the dividend or the divisor as a float.
  29. >
  30. I think the preferred solution is to use
  31.  
  32.    n = 9.0 / 5.0;
  33.  
  34. Remember that 9 and 5 are integers but 9.0 and 5.0 are floating point types.
  35. Use the ones that are consistent with the rest of your expression.
  36.  
  37. Also, you are not using math.h in this program so you can delete
  38. #include <math.h>
  39.  
  40.  
  41.